<%@ page import="schoolsource.sql.SchoolDBSQL" %>
<%@ page import="schoolsource.model.*" %>
<%@ page import="schoolsource.security.SecurityToken" %>
<%@ page import="schoolsource.gui.FormFields" %>
<% SecurityToken st = (SecurityToken) request.getAttribute(FormFields.SESSION);
   String token = (String) st.getValue(FormFields.TOKEN);
   ContactContainer commC[] = (ContactContainer[]) st.getValue("communicationContainer");
   UserContainer teacherContainer = (UserContainer) st.getValue("teacherContainer");
   UserContainer studentWhoSentMail[] = (UserContainer[]) st.getValue("studentWhoSentMail");
   int classnum = (new Integer((String) st.getValue(FormFields.CLASSNUM))).intValue();
   UserContainer fullStudentAndParentList[][];
   if (classnum != -2) {
       fullStudentAndParentList = (UserContainer[][]) st.getValue("studentAndParentList");
   }
   else {
       fullStudentAndParentList = new UserContainer[0][0];
   }
   boolean parent = (st.getValue("parent") != null);
   boolean reply = ("Reply".equals(request.getParameter(FormFields.BUTTONCLICKED)));
   if (!reply) {
     reply = ("Reply".equals(request.getParameter(FormFields.LINKCLICKED)));
   }
   ClassContainer classC[] = (ClassContainer[]) st.getValue("classContainer");
   int mailnum = (new Integer((String) st.getValue(FormFields.MAILNUM))).intValue(); 
   String loginType = (String) request.getAttribute(FormFields.USRTYPE); 
   String schoolName = (String) request.getAttribute(FormFields.SCHOOLNAME);
%>


<HTML>
  <HEAD>
    <SCRIPT LANGUAGE="JavaScript">
        var availableStudentArray = new Array();
        var availableParentArray = new Array();
        var assignedRecipientArray = new Array();
        var d = top.frames.viewframe.document;
//        var padding = "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
//        var padding = "                                                            ";
        var padding = "                               ";
        
        <% 
            if (mailnum == -1) {
                out.println("function init() { ");
                for (int i = 0; i < fullStudentAndParentList.length; i++) {
                    out.println("insertOptionIntoArray(availableStudentArray, \"" + fullStudentAndParentList[i][0].getAssignedID().toString() + "\", \"S\", \"" + fullStudentAndParentList[i][0].getLastName().toString() + ",\", \"" + fullStudentAndParentList[i][0].getFirstName().toString() + "\");");
                    out.println("insertOptionIntoList(d.forms[0].studentList, \"" + fullStudentAndParentList[i][0].getAssignedID().toString() + "\", \"" + fullStudentAndParentList[i][0].getLastName().toString() + ", " + fullStudentAndParentList[i][0].getFirstName().toString() + "\");");
                    for (int j = 1; j < fullStudentAndParentList[i].length; j++) {
                        out.println("insertOptionIntoArray(availableParentArray, \"" + fullStudentAndParentList[i][j].getAssignedID().toString() + "\", \"P\", \"" + fullStudentAndParentList[i][j].getLastName().toString()+",\", \"" + fullStudentAndParentList[i][j].getFirstName().toString() + "\");");
                        out.println("insertOptionIntoList(d.forms[0].parentList, \"" + fullStudentAndParentList[i][j].getAssignedID().toString() + "\", \"" + fullStudentAndParentList[i][j].getLastName().toString() + ", " + fullStudentAndParentList[i][j].getFirstName().toString() + "\");");
                    }
                }
                out.println("        }");
            }
        %>

        function existsInArray(anArray, key) {
            for (var i in anArray) {
                if (anArray[i][0] == key) {
                    return true;
                }
            }
            
            return false;
        }
        
        function existsInList(aList, key) {
            for (var i = 0; i < aList.length; i++) {
                if (aList[i].value == key) {
                    return true;
                }
            }
            
            return false;
        }

        function insertOptionIntoArray(anArray, avalue, bvalue, cvalue, dvalue) {
            if (!existsInArray(anArray, avalue)) {
            	anArray[anArray.length] = new Array(4);

//                var newArray = new Array();
                anArray[anArray.length-1][0] = avalue;
                anArray[anArray.length-1][1] = bvalue;
                anArray[anArray.length-1][2] = cvalue;
                anArray[anArray.length-1][3] = dvalue;
//                anArray.push(newArray);
            }
        }
        
        function insertOptionIntoList(selectList, value, text) {
            if (!existsInList(selectList, value)) {
                var o = new Option(text, value);
                var temp;
                for (var i = 0; i < selectList.length; i++) {
                    if (selectList[i].text > o.text) {
                        temp = selectList[i];
                        selectList[i] = o;
                        o = temp;
                    }
                }
                selectList[selectList.length]=o;
            }
        }
        
        function removeOptionFromArray(anArray, key) {
//            var tempArray;
//            var returnVal = null;
//            for (var i = 0; i < anArray.length; i++) {
//                if (anArray[i][0] == key) {
//                    returnVal = anArray.splice(i, 1)[0];
//                    return returnVal;
//                }
//            }
			var returnVal = null;
			for (var i = 0; i < anArray.length; i++) {
				if (anArray[i][0] == key) {
					returnVal = anArray[i];
					var j = i + 1;
					for (; j < anArray.length; j++, i++) {
						anArray[i] = anArray[j];
					}
					anArray[j] = null;
					anArray.length = j;
			
					return returnVal;
				}
			}
        }
        
        function removeOptionFromList(selectList, key) {
            var returnVal = null;
            for (var i = 0; i < selectList.length; i++) {
                if (selectList[i].value == key) {
                    returnVal = selectList[i];
                    selectList[i] = null;
                    return returnVal;
                }
            }
        }

        function selectStudent() {
            var selectedValues = new Array();
            var w = top.frames.viewframe;
            var d = w.document;
            var sList = d.forms[0].studentList;
            var dest = d.forms[0].recipientList;
            var counter = 0;

            for (var i = 0; i < sList.length; i++) {
                var arrayTemp = null;
                var listTemp = null;
                if (sList[i].selected) {
                    arrayTemp = removeOptionFromArray(availableStudentArray, sList[i].value);
                    insertOptionIntoArray(assignedRecipientArray, arrayTemp[0], arrayTemp[1], arrayTemp[2], arrayTemp[3]);
                    listTemp = removeOptionFromList(sList, sList[i].value);
                    insertOptionIntoList(dest, listTemp.value, listTemp.text);
                i--;
                }
            
            }
        }
        
        function selectParent() {
            var selectedValues = new Array();
            var w = top.frames.viewframe;
            var d = w.document;
            var pList = d.forms[0].parentList;
            var dest = d.forms[0].recipientList;
            var counter = 0;

            for (var i = 0; i < pList.length; i++) {
                var arrayTemp = null;
                var listTemp = null;
                if (pList[i].selected) {
                    arrayTemp = removeOptionFromArray(availableParentArray, pList[i].value);
                    insertOptionIntoArray(assignedRecipientArray, arrayTemp[0], arrayTemp[1], arrayTemp[2], arrayTemp[3]);
                    listTemp = removeOptionFromList(pList, pList[i].value);
                    insertOptionIntoList(dest, listTemp.value, listTemp.text);
                i--;
                }
            }
        }

        function unselectRecipient() {
            var selectedValues = new Array();
            var w = top.frames.viewframe;
            var d = w.document;
            var sList = d.forms[0].studentList;
            var pList = d.forms[0].parentList;
            var sele = d.forms[0].recipientList;
            var counter = 0;

            for (var i = 0; i < sele.length; i++) {
                var arrayTemp = null;
                var listTemp = null;
                if (sele[i].selected) {
                    arrayTemp = removeOptionFromArray(assignedRecipientArray, sele[i].value);
                    if (arrayTemp[1] == "S") {
                        insertOptionIntoArray(availableStudentArray, arrayTemp[0], arrayTemp[1], arrayTemp[2], arrayTemp[3]);
                        listTemp = removeOptionFromList(sele, sele[i].value);
                        insertOptionIntoList(sList, listTemp.value, listTemp.text);
                    }
                    else {
                        insertOptionIntoArray(availableParentArray, arrayTemp[0], arrayTemp[1], arrayTemp[2], arrayTemp[3]);
                        listTemp = removeOptionFromList(sele, sele[i].value);
                        insertOptionIntoList(pList, listTemp.value, listTemp.text);
                    }
                i--;
                }
            }
        }
        
        
        
        function buildRecipientString() {
            var result = "";
            document.forms[0].<%= FormFields.LINKCLICKED %>.value = "Send";
            if (assignedRecipientArray.length == 0) {
            	alert("You have not selected any recipients. Please select one or more and resubmit.");
            	return false;
            }
            else {
	            for (var i=0; i < assignedRecipientArray.length; i++) {
	                if (i == 0) {
	                    result = assignedRecipientArray[i][0];
	                }
	                else {
	                    result = result + "," + assignedRecipientArray[i][0];
	                }
	            }
	            document.forms["mailform"].<%= FormFields.ASSIGNEDRECIPIENTS %>.value = result;
	            return true;
	        }
        }
        
        function submitNewMail() {
            document.forms[0].<%= FormFields.LINKCLICKED %>.value = "Send";
            if (assignedRecipientArray.length == 0) {
            	alert("You have not selected any recipients. Please select one or more and resubmit.");
            }
            else {
            	buildRecipientString();
            	document.forms[0].submit();
            }
        }
        
        function submitReply() {
            document.forms[0].<%= FormFields.LINKCLICKED %>.value = "Send";
            <%= FormFields.ASSIGNEDRECIPIENTS %>.value = <%= SchoolDBSQL.CTTOID %>.value;
            document.forms[0].submit();
        }

        function cancelForm() {
            document.forms[0].<%= FormFields.LINKCLICKED %>.value = "Cancel";
            document.forms[0].submit();
        }

        // the following function, setCaretLocation, was borrowed from
        // http://groups.yahoo.com/group/wdf-dom/message/3759 -- Alex Russell
            function setCaretLocation(location, textareaNode){
                // the index of the position you'd like the cursor at
                var loc = parseInt(location);
                // reference a shorter name
                var twe = textareaNode;
                if (twe.setSelectionRange) {
                    twe.focus();
                    twe.setSelectionRange(loc, loc);
                }
                else if (twe.createTextRange) {
                    var range = twe.createTextRange();
                    range.collapse(true);
                    range.moveEnd('character', loc);
                    range.moveStart('character', loc);
                    range.select();
                } 
                else { //otherwise try a moz specific hack
                    // not sure if these are really necessaray
                    twe.value = twe.value;
                    twe.blur(); twe.focus();
                    // figure out how far "back" to go.
                    var dist = parseInt(twe.value.length)-loc;
                    // a left arrow char (hopefully?)
                    var tchar = String.fromCharCode(37);
                    for(var x = 0; x < dist; x++){
                        /* see Mozilla LXR for more info about this constructor
                           http://lxr.mozilla.org/seamonkey/source/content/events/src/
                           nsDOMEvent.cpp#1289*/
                       var te = document.createEvent("KeyEvents");
                       te.initKeyEvent("keypress", true, true,
                       null, false, false, false,
                       false, tchar.charCodeAt(0),
                       tchar.charCodeAt(0));
                       twe.dispatchEvent(te);
                    }
                }
            }
            
            function initForm() {
                document.forms[0].<%= SchoolDBSQL.MSGBODY %>.focus();
                setCaretLocation(-1, document.forms[0].<%= SchoolDBSQL.MSGBODY %>);
            }
            
    </SCRIPT>
  </HEAD>
  <BODY<%= ((mailnum == -1) ? " onLoad=\"init()\"" : "") %><%= (reply) ? " onLoad=\"initForm();\"" : "" %>>

    <FORM Style="font-family:sans-serif;font-size:12;"; NAME="mailform" METHOD="POST" onSubmit="return false;">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.ASSIGNEDRECIPIENTS %>" VALUE="">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CURRENT %>" VALUE="<%= FormFields.SUBFRAME %>">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.TOKEN %>" VALUE="<%= token %>">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.PARAMETER %>" VALUE="">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CLASSNUM %>" VALUE="<%= classnum %>">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.LINKCLICKED %>" VALUE="">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.SCHOOLNAME %>" VALUE="<%= schoolName %>">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.USRTYPE %>" VALUE="<%= loginType %>">
  <% 
     if (mailnum != -1 && !reply) {
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + SchoolDBSQL.CTTOID + "\" VALUE=\"" + teacherContainer.getAssignedID().toString() + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + SchoolDBSQL.CTFROMID + "\" VALUE=\"" + studentWhoSentMail[mailnum].getAssignedID().toString() + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FormFields.FORMFROMPARENT + "\" VALUE=\"" + (parent ? "TRUE" : "FALSE") + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FormFields.FORMFROMSTUDENT + "\" VALUE=\"" + (parent ? "FALSE" : "TRUE") + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FormFields.MAILNUM + "\" VALUE=\"" + mailnum + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + SchoolDBSQL.CLASSASSIGNEDID + "\" VALUE=\"" + commC[mailnum].getClassAssignedID().toString() + "\">");

        out.println("<TABLE Style=\"font-family:sans-serif;font-size:12;\";><TR><TD><B>To:&nbsp;&nbsp;</B>");
        out.println("</TD>");
        out.println("<TD>"+teacherContainer.getFirstName().toString() + " " + teacherContainer.getLastName().toString() + "</TD></TR><br>");

        out.println("<TR><TD><B>From:&nbsp;&nbsp;</B>");
        if (parent) {
            out.println("The parents of ");
        }
        out.println("</TD>");
        out.println("<TD>"+studentWhoSentMail[mailnum].getFirstName().toString() + " " + studentWhoSentMail[mailnum].getLastName().toString() + "</TD></TR><br>");
        out.println("<TR><TD><B>Subject:&nbsp;&nbsp;</B></TD><br>");
        out.println("<TD>" + commC[mailnum].getMessage().getSubject().toString() + "</TD></TR><br>");
        out.println("</TABLE><hr><TABLE Style=\"font-family:sans-serif;font-size:12;\";><br>");
        StringBuffer body = new StringBuffer(commC[mailnum].getMessage().getMessageBody().toString());
        int linebreakIndex = 0;
        for (int i = 0; i < body.length(); i++) {
            if ((int) body.charAt(i) == 13) {
                body.replace(i, i + 1, "<BR>");
            }
        }
        out.println("<TR><TD>"+body.toString()+"</TD></TR></TABLE>");

     }
     else if (mailnum == -1) {
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + SchoolDBSQL.CTFROMID + "\" VALUE=\"" + teacherContainer.getAssignedID().toString() + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FormFields.FORMFROMPARENT + "\" VALUE=\"" + (parent ? "TRUE" : "FALSE") + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FormFields.FORMFROMSTUDENT + "\" VALUE=\"" + (parent ? "FALSE" : "TRUE") + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + SchoolDBSQL.CLASSASSIGNEDID + "\" VALUE=\"" + classC[classnum].getClassAssignedID().toString() + "\">");
        out.println("<TABLE Style=\"font-family:sans-serif;font-size:12;\";>");
        out.println("  <TR>");
        out.println("    <TD WIDTH=\"60\">&nbsp;<B>To:&nbsp;</B></TD>");
        out.println("                <TD COLSPAN=\"5\">");
        out.println("                    <TABLE Style=\"font-size:13;\";>");
        out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\"><B>Students</B></TD>");
        out.println("                            <TD>&nbsp</TD>");
        out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\"><B>Parents</B></TD>");
        out.println("                            <TD>&nbsp</TD>");
        out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\"><B>Recipients</B></TD>");
        out.println("                        <TR>");
        out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\">");
        out.println("                              <SELECT NAME=\"studentList\" MULTIPLE=\"YES\" SIZE=\"6\" STYLE=\"font-family:sans-serif;font-size:11;WIDTH:200PX\"");
        out.println("                            </TD>");
        out.println("                            <TD>&nbsp</TD>");
        out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\">");
        out.println("                              <SELECT NAME=\"parentList\" MULTIPLE=\"YES\" SIZE=\"6\" STYLE=\"font-family:sans-serif;font-size:11;WIDTH:200PX\"");
        out.println("                            </TD>");
        out.println("                            <TD>&nbsp;&nbsp;<INPUT TYPE=\"BUTTON\" VALUE=\"-->\" onClick='selectParent(); selectStudent();'>&nbsp;&nbsp;<BR>");
        out.println("                                &nbsp;<BR>");
        out.println("                                &nbsp;&nbsp;<INPUT TYPE=\"BUTTON\" VALUE=\"<--\" onClick='unselectRecipient()'>&nbsp;&nbsp;");
        out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\">");
        out.println("                              <SELECT NAME=\"recipientList\" MULTIPLE=\"YES\" SIZE=\"6\" STYLE=\"font-family:sans-serif;font-size:11;WIDTH:200PX\"></SELECT>");
        out.println("                            </TD>");
        out.println("                        </TR>");
        out.println("                    </TABLE>");
        out.println("                </TD>");
        out.println("            </TR>");
        out.println("<TR>");
        out.println("<TD>");
        out.println("&nbsp;<B>From:&nbsp;&nbsp;</B></TD>");
        out.println("<TD>");
        out.println(teacherContainer.getFirstName() + " " + teacherContainer.getLastName());
        out.println("</TR>");
        out.println("<TR>");
        out.println("<TD>");
        out.println("&nbsp;<B>Subject:&nbsp;&nbsp;</B></TD>");
        out.println("<TD>");
        String subject = "";
        out.println("<INPUT Style=\"font-family:sans-serif;font-size:12;\"; TYPE=\"TEXT\" NAME=\"" + SchoolDBSQL.MSGSUBJECT + "\" VALUE=\"" + subject + "\" SIZE=\"82\"></TD>");
        out.println("</TR>");
        out.println("</TABLE>");
        out.println("<hr>");
        out.println("<TEXTAREA Style=\"font-family:sans-serif;font-size:12;\"; NAME=\"" + SchoolDBSQL.MSGBODY + "\" COLS=\"122\" ROWS=\"11\" VALUE=\"\" SCROLLING='NO'>");
        if (reply) {
            out.println("\n\n<---- original message ---->");
            out.println(commC[mailnum].getMessage().getMessageBody().toString());
        }
        out.println("</TEXTAREA><BR>");
        
        out.println("<CENTER><INPUT TYPE=\"BUTTON\" NAME=\"" + FormFields.BUTTONCLICKED + "\" onClick=\"" + ((reply) ? "submitReply()" : "submitNewMail()") + ";\" VALUE=\"Send\">  ");
        out.println("<INPUT TYPE=\"BUTTON\" NAME=\"" + FormFields.BUTTONCLICKED + "\" onClick=\"cancelForm();\" VALUE=\"Cancel\"></CENTER>");
//        out.println("<CENTER><INPUT TYPE=\"SUBMIT\" NAME=\"" + FormFields.BUTTONCLICKED + "\" VALUE=\"Send\">  ");
//        out.println("<INPUT TYPE=\"SUBMIT\" NAME=\"" + FormFields.BUTTONCLICKED + "\" VALUE=\"Cancel\"></CENTER>");
     }
     else {
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + SchoolDBSQL.CTFROMID + "\" VALUE=\"" + teacherContainer.getAssignedID().toString() + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FormFields.FORMFROMPARENT + "\" VALUE=\"" + (parent ? "TRUE" : "FALSE") + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FormFields.FORMFROMSTUDENT + "\" VALUE=\"" + (parent ? "FALSE" : "TRUE") + "\">");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + SchoolDBSQL.CLASSASSIGNEDID + "\" VALUE=\"" + classC[classnum].getClassAssignedID().toString() + "\">");
        out.println("<TABLE Style=\"font-family:sans-serif;font-size:12;\";>");
        out.println("<TR>");
        out.println("<TD WIDTH=\"60\">");
        out.println("&nbsp;<B>To: &nbsp;&nbsp;</B></TD>");
        out.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + SchoolDBSQL.CTTOID + "\" VALUE=\"" + studentWhoSentMail[mailnum].getAssignedID().toString() + "\">");
        out.println("<TD>");
        out.println(studentWhoSentMail[mailnum].getFirstName() + " " + studentWhoSentMail[mailnum].getLastName());
        out.println("</TD>");
        out.println("</TR>");
        out.println("<TR>");
        out.println("<TD>");
        out.println("&nbsp;<B>From:&nbsp;&nbsp;</B></TD>");
        out.println("<TD>");
        out.println(teacherContainer.getFirstName() + " " + teacherContainer.getLastName());
        out.println("</TR>");
        out.println("<TR>");
        out.println("<TD>");
        out.println("&nbsp;<B>Subject:&nbsp;&nbsp;</B></TD>");
        out.println("<TD>");
//        String subject = (reply ? "RE: " + commC[mailnum].getMessage().getSubject().toString() : "");
        String subject;
        if (reply) {
            if (commC[mailnum].getMessage().getSubject().toString().length() > 2 &&
                commC[mailnum].getMessage().getSubject().toString().substring(0, 3).equals("RE:")) {
                subject = commC[mailnum].getMessage().getSubject().toString();
            }
            else {
                subject = "RE: " + commC[mailnum].getMessage().getSubject().toString();
            }
        }
        else {
            subject = "";
        }
        out.println("<INPUT  Style=\"font-family:sans-serif;font-size:12;\"; TYPE=\"TEXT\" NAME=\"" + SchoolDBSQL.MSGSUBJECT + "\" VALUE=\"" + subject + "\" SIZE=\"82\"></TD>");
        out.println("</TR>");
        out.println("</TABLE>");
        out.println("<hr>");
        out.println("<TEXTAREA Style=\"font-family:sans-serif;font-size:12;\"; NAME=\"" + SchoolDBSQL.MSGBODY + "\" COLS=\"122\" ROWS=\"11\" VALUE=\"\" SCROLLING='NO'>");
        if (reply) {
            out.println("\n\n<---- original message ---->");
            out.println(commC[mailnum].getMessage().getMessageBody().toString());
        }
        out.println("</TEXTAREA><BR>");
        out.println("<CENTER><INPUT TYPE=\"BUTTON\" NAME=\"" + FormFields.BUTTONCLICKED + "\" onClick=\"" + ((reply) ? "submitReply()" : "submitNewMail()") + ";\" VALUE=\"Send\">  ");
//        out.println("<CENTER><INPUT TYPE=\"BUTTON\" NAME=\"" + FormFields.BUTTONCLICKED + "\" onClick=\"submitForm();\" VALUE=\"Send\">  ");
        out.println("<INPUT TYPE=\"BUTTON\" NAME=\"" + FormFields.BUTTONCLICKED + "\" onClick=\"cancelForm();\" VALUE=\"Cancel\"></CENTER>");
     } %>
    </FORM>
  </BODY>
</HTML>